a,n=map(int,input().split())
t=list(map(int,input().split()))
NbC=0
for i in range(a):
D=abs(n-1-i)
if n-1>i:
if t[i] and n-1+D<a and t[n-1+D]:
NbC+=1
elif t[i] and (n-1+D>=a or i==n-1):
NbC+=1
else:
if t[i] and n-1-D>-1 and t[n-1-D]:
NbC+=1
elif t[i] and (n-1-D<0 or i==n-1):
NbC+=1
print(NbC)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,a,cnt=0;
cin>>n>>a;
int c[n];
int l=a-2,r=a;
for(int i=0;i<n;i++) cin>>c[i];
while(r<n || l>=0)
{
if(l>=0 && r<n && c[l]==1 && c[r]==1)
cnt+=2;
else if(l>=0 && c[l]==1 && r>=n) cnt++;
else if(r<n && c[r]==1 && l<0) cnt++;
l--;
r++;
}
if(c[a-1]==1) cnt++;
cout<<cnt;
return 0;
}
1728A - Colored Balls Revisited | 276B - Little Girl and Game |
1181A - Chunga-Changa | 1728C - Digital Logarithm |
1728D - Letter Picking | 792B - Counting-out Rhyme |
1195A - Drinks Choosing | 5D - Follow Traffic Rules |
1272A - Three Friends | 1632D - New Year Concert |
1400D - Zigzags | 716C - Plus and Square Root |
412A - Poster | 844B - Rectangles |
1591A - Life of a Flower | 1398C - Good Subarrays |
629A - Far Relative’s Birthday Cake | 1166A - Silent Classroom |
1000B - Light It Up | 218B - Airport |
1463B - Find The Array | 1538C - Number of Pairs |
621B - Wet Shark and Bishops | 476B - Dreamoon and WiFi |
152C - Pocket Book | 1681D - Required Length |
1725D - Deducing Sortability | 1501A - Alexey and Train |
721B - Passwords | 1263D - Secret Passwords |